//
//  JWScheduleModel.m
//  SiqiCalendar
//
//  Created by sunjiawen on 2018/4/4.
//  Copyright © 2018年 sjw. All rights reserved.
//

#import "JWScheduleModel.h"

@implementation JWScheduleModel
+ (NSString *)primaryKey {
    return kScheduleId;
}

+ (NSArray<NSString *> *)ignoredProperties {
    return @[kScheduleColor];
}

- (UIColor *)scheduleColor {
    return [[UtiliTools utilShareIntance] strToColor:self.scheduleColorStr];
}

- (void)setScheduleColor:(UIColor *)scheduleColor {
    self.scheduleColorStr = [[UtiliTools utilShareIntance] colorToNSString:scheduleColor];
}

- (void)updateScheduleColorStr: (NSString *)scheduleColorStr {
    if ([scheduleColorStr isEqualToString:self.scheduleColorStr]) return;
    
    RLMRealm *realm = [RLMRealm defaultRealm];
    JWScheduleModel *schedule = [JWScheduleModel objectsWhere:@"scheduleId = %@",self.scheduleId].firstObject;
    
    [realm transactionWithBlock:^{
        schedule.scheduleColorStr = scheduleColorStr;
    }];
}

- (void)updateOrderIndex: (NSNumber *)orderIndex {
    if (orderIndex.integerValue == orderIndex.integerValue) return;
    
    RLMRealm *realm = [RLMRealm defaultRealm];
    JWScheduleModel *schedule = [JWScheduleModel objectsWhere:@"scheduleId = %@",self.scheduleId].firstObject;
    
    [realm transactionWithBlock:^{
        schedule.orderIndex = orderIndex;
    }];
}
@end
